package com.ft.mybatis.service.dto;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ft.core.service.dto.BaseDto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

/**
 * @copyright (C), 2015-2019, XXX有限公司
 * @fileName: BaseQueryPageInput
 * @author: 李阳
 * @date: 2019/6/26 16:28
 * @description: 公共分页查询参数基类
 * @history: <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
@Getter
@Setter
public class BaseQueryPageInput extends BaseDto {
    private static final long serialVersionUID = 6045638890035296075L;

    private static final long MIN_SIZE = 10;
    private static final long MIN_CURRENT = 1;

    public BaseQueryPageInput() {
    }

    /**
     * 分页构造函数
     *
     * @param current 当前页
     * @param size    每页显示条数
     */
    public BaseQueryPageInput(long current, long size) {
        if (current > MIN_CURRENT) {
            this.current = current;
        }
        if (size > MIN_SIZE) {
            this.size = size;
        }
    }

    /**
     * 每页显示条数，默认 10
     */
    @ApiModelProperty(value = "每页显示条数", required = true)
    private long size = 10;
    /**
     * 当前页
     */
    @ApiModelProperty(value = "当前页码", required = true)
    private long current = 1;

    /**
     * 转换为MybatisPlus的Page对象
     *
     * @return
     */
    public Page toMybatisPageObject() {
        return new Page(this.current, this.size);
    }
}
